package com.lovingtour.manager.merchant;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.lovingtour.manager.R;
import com.lovingtour.manager.util.ApplicationUtils;

public class MerchantRechargeCountActivity extends Activity implements
		OnClickListener, TextWatcher {

	private Button btnRechargemoney;
	private EditText etAccount;
	private EditText etRechargeCount;
	private TextView tvShowCountMoney;
	private LinearLayout lNotice;
	private ImageButton ibBack;
	private LinearLayout l1,l2;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.merchant_rechargeticket);
		initView();
		initData();
		initListener();
	}

	private void initView() {
		btnRechargemoney = (Button) findViewById(R.id.btn_rechargemoney);
		etAccount = (EditText) findViewById(R.id.et_account);
		etRechargeCount = (EditText) findViewById(R.id.et_count);
		tvShowCountMoney = (TextView) findViewById(R.id.tv_needpaymoney);
		lNotice = (LinearLayout) findViewById(R.id.lNotice);
		ibBack = (ImageButton) findViewById(R.id.ib_back);
		l1 = (LinearLayout) findViewById(R.id.l1);
		l2 = (LinearLayout) findViewById(R.id.l2);
	}

	private void initData() {
		lNotice.setVisibility(View.GONE);
	}

	private void initListener() {
		btnRechargemoney.setOnClickListener(this);
		etRechargeCount.addTextChangedListener(this);
		ibBack.setOnClickListener(this);
		l1.setOnClickListener(this);
		l2.setOnClickListener(this);
	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		switch (v.getId()) {
		case R.id.btn_rechargemoney:
			Intent intent = new Intent(this, MerchantBuyDetailActivity.class);
			startActivity(intent);
			break;
		case R.id.ib_back:
			finish();
			break;
		case R.id.l1:
			etAccount.requestFocus();
			break;
		case R.id.l2:
			etRechargeCount.requestFocus();
			break;
		default:
			break;
		}
	}

	@Override
	public void beforeTextChanged(CharSequence s, int start, int count,
			int after) {
		// TODO Auto-generated method stub
	}

	@Override
	public void onTextChanged(CharSequence s, int start, int before, int count) {
		// TODO Auto-generated method stub
		Log.i("abc", "onTextChanged : s = " + s.toString() + ",start = "
				+ start + ",before = " + before + ",count = " + count);

		if ("".equals(s.toString())) {
			lNotice.setVisibility(View.GONE);
			tvShowCountMoney.setText("");
		} else {
			lNotice.setVisibility(View.VISIBLE);
			tvShowCountMoney.setText(ApplicationUtils.format2Renminbi(Long
					.parseLong(s.toString())));
		}
	}

	@Override
	public void afterTextChanged(Editable s) {
		// TODO Auto-generated method stub
		
	}

}
